//
//  UIImageView+Extension.m
//  Practice
//
//  Created by yons on 14.8.20.
//  Copyright © 2020 yons. All rights reserved.
//

#import "UIImageView+Extension.h"
#import "UIImage+SMExtension.h"

@implementation UIImageView (Extension)

/// 类方法
+ (UIImageView *)imageView {
    UIImageView *imageView = [[UIImageView alloc] init];
    return imageView;
}

/// 图片
/// @param imageName 图片名称
+ (UIImageView *)imageViewWithImageName:(NSString *)imageName {
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage sm_imageWithNamed:imageName]];
    return imageView;
}

/// 背景色
/// @param backgroundColor 背景色
+ (UIImageView *)imageViewWithBackgroundColor:(UIColor *)backgroundColor {
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.backgroundColor = backgroundColor;
    return imageView;
}

/// 剪切半径
/// @param radius 剪切半径
+ (UIImageView *)imageViewWithCornerRadius:(CGFloat)radius {
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.userInteractionEnabled = YES;
    imageView.layer.cornerRadius = radius;
    imageView.clipsToBounds = YES;
    return imageView;
}

/// 剪切半径+边框宽度+边框颜色
/// @param radius 剪切半径
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
+ (UIImageView *)imageViewWithCornerRadius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor {
    UIImageView *imageView = [self imageViewWithCornerRadius:radius];
    imageView.layer.borderWidth = borderWidth;
    imageView.layer.borderColor = borderColor.CGColor;
    return imageView;
}

/// 添加点击方法
/// @param target target
/// @param action 方法
- (void)addTarget:(nullable id)target action:(nullable SEL)action {
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
    self.userInteractionEnabled = YES;
    [self addGestureRecognizer:tapGesture];
}

@end
